package com.controller;

import com.context.conexion.EnahoConexion;
import com.model.domain.dinero.ConceptoPagoPersonal;
import com.model.domain.dinero.Partida;
import com.model.domain.dinero.ConglomeradoPersonalDetalle;
import com.model.domain.dinero.ConglomeradoPersonalResumen;
import com.model.domain.persona.Personal;
import com.model.domain.tiempo.Periodo;
import com.model.domain.ubicacion.Conglomerado;
import com.model.service.ConceptoPagoPersonalService;
import com.model.service.PeriodoService;
import java.sql.Connection;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONObject;

/**
 *
 * @author rdelacruz
 */
public class ConceptoPagoPersonalController 
extends AbstractController
{   
   public void json(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Connection con = null;    
        try {
            con = EnahoConexion.getConexion();   
            
            ConglomeradoPersonalDetalle filtro = new ConglomeradoPersonalDetalle();
            ConglomeradoPersonalResumen cpr = new ConglomeradoPersonalResumen();
            filtro.setConglomeradoPersonalResumen(cpr);
            
            Conglomerado c = new Conglomerado();
            c.setCodigo(request.getParameter("conglomerado"));
            cpr.setConglomerado(c);
            
            Personal p =  new Personal();
            p.setDni(request.getParameter("personal"));
            cpr.setPersonal(p);
            
            Partida par = new Partida();
            par.setCodigo(request.getParameter("partida"));                    
            filtro.setPartida(par);

            ConceptoPagoPersonalService service = (ConceptoPagoPersonalService) this.getService();            
            ConceptoPagoPersonal cp = service.findByFiltro(con,filtro);            

            JSONObject json = new JSONObject();
            if(cp.getMonto()!=null)
                json.append("monto", cp.getMonto());
            response.getWriter().append(json.toString());
        }
        finally {
            if(con!=null) con.close();
        }
   }
}
